<template>
  <div class="home">
    <home-header></home-header>
    <home-swiper :swiper="swiperList"></home-swiper>
    <!-- <com>
      <template #header>
        <h1>Here might be a page title</h1>
      </template>
      <template v-slot:footer>
        <h3>footer</h3>
      </template> -->
      <!-- <div>
        <div>content</div>
        <div>content</div>
        <div>content</div>
        <div>content</div>
      </div> -->
      <!-- <template v-slot:default="prop">{{ prop.obj.name }} {{ prop.obj.age }}</template> -->
      <!-- <template v-slot:default="{obj}">{{ obj.name }} {{ obj.age }}</template> -->
      <!-- <div>
        
      </div> -->
      <!-- <template v-slot="prop2">{{ prop2.obj.name }}</template> -->
      <!-- <template v-slot:default="prop3">{{ prop3.obj.name }}</template> -->
    <!-- </com> -->
    <!-- <test :on-click="ccc" :is-show="show"></test> -->
    <test :onClick="ccc" :isShow="show"></test>
    <home-icons :icons="iconList"></home-icons>
    <home-recommend :recommendList="recommendList"></home-recommend>
    <home-weekend :weekendList="weekendList"></home-weekend>
  </div>
</template>

<script>
import HomeHeader from "./components/Header";
import HomeSwiper from "./components/Swiper";
import HomeIcons from "./components/Icons";
import HomeRecommend from "./components/Recommend";
import HomeWeekend from "./components/Weekend";
import com from "./components/com";
import test from "./components/test";
import axios from "axios";
import { mapState } from "vuex";
import Test from './components/test.vue';

export default {
  name: "Home",
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend,
    com,
    test
  },
  data() {
    return {
      lastCity: "",
      iconList: [],
      recommendList: [],
      swiperList: [],
      weekendList: [],
      show: true
    };
  },
  computed: {
    ...mapState(["city"]),
  },
  methods: {
    ccc() {
      this.show = !this.show
    },
    getHomeInfo() {
      axios.get("/api/index.json?city=" + this.city).then(this.renderHome);
    },
    renderHome(res) {
      let datas = res.data;
      // console.log(datas)
      if (datas.ret && datas.data) {
        this.iconList = datas.data.iconList;
        this.recommendList = datas.data.recommendList;
        this.swiperList = datas.data.swiperList;
        this.weekendList = datas.data.weekendList;
      }
    },
    async testAxync() {
      return "hello";
    },
    te() {
      // return setTimeout(()=>{
      // return 'answer'
      // },2000)
      return new Promise((res) => {
        res("answer");
      });
    },
  },
  async mounted() {
    this.lastCity = this.city;
    this.getHomeInfo();
    // let res = this.testAxync();
    // console.log(res);
    // let test = this.te();
    // console.log(test);
    await this.te().then((res) => {
      console.log(res);
    });
    // let text = await this.te();
    // console.log(text);
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city;
      this.getHomeInfo();
    }
  }
};
</script>

<style scoped>
</style>
